<?php
namespace manage;

require_once __DIR__ . '/Lib/Base.php';

use \Model\UserModel;

use Workerman\Protocols\Http;
if(!Http::sessionStarted()) Http::sessionStart();
checkLogin();

// 权限检查
$funcs = getFuncs($_SESSION['admin_group']);
if(!in_array(8, $funcs)) {
    echo '<script type="text/javascript">location.href="dashboard.php";</script>';
    #Http::header('Location:dashboard.php');
    return;
}

global $plat_db;

$error = $success = NULL;
$now = time();
$today = date('Y-m-d');


$show_config = [];
$file = __DIR__ . '/../c.txt';
// if (!$infoconfig1 || !$infoconfig2) {
    $f = fopen($file, 'r');
    $infoconfig = trim(fgets($f));
    fclose($f);
    // $line_arr = explode('^', $line);
    // $infoconfig1 = $line_arr[0];
    // $infoconfig2 = $line_arr[1];
    $show_config = json_decode($infoconfig, true);
    
// }else{
//  if (strpos($infoconfig1,':') === false || strpos($infoconfig2,':') === false) {
//      $error = '格式无效,应填入格式为描述文字:微信号';
//  }else{
//      $line = $infoconfig1.'^'.$infoconfig2;
//      file_put_contents($file, $line);
//  }
    
//  //file_put_contents($file, $infoconfig2, FILE_APPEND);
// }

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | General Form Elements</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="http://gold-static.91changwan.com/web/manage_static/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="http://gold-static.91changwan.com/web/manage_static/bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="http://gold-static.91changwan.com/web/manage_static/bower_components/Ionicons/css/ionicons.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="http://gold-static.91changwan.com/web/manage_static/bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="http://gold-static.91changwan.com/web/manage_static/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="http://gold-static.91changwan.com/web/manage_static/dist/css/skins/_all-skins.min.css">

    <link rel="stylesheet" href="http://gold-static.91changwan.com/web/manage_static/plugins/iCheck/all.css">
    <style>
        .small-box-footer {height:40px; line-height:35px;}
        .data_table th {font-size:14px; color:#666; font-weight:normal; width:180px; text-align:center;}
        .data_table td {font-size:18px; font-weight:normal;text-align:right;}
        .data_table td small {font-size:12px; color:#888;margin-left:3px;}
        .data_table td div {padding:0;}
        td,th {vertical-align:middle !important;}
        .filter_box {font-size:12px;}
        .filter_box div {border:1px solid #4b97c4; border-radius:5px; padding:4px 7px; margin-right:5px; margin-left:10px; display:inline-block; padding-right:0 !important;}
        .filter_box div strong {color:#155;}
        .filter_box div span.badge {position:relative; left:11px; top:-15px; cursor:pointer;}
        .filter_box div span.badge:hover {background:#f70 !important; color:#ff0 !important;}
        #control_table th {font-weight:normal;font-size:12px;background:#fafafa;color:#343;}
    </style>
</head>

<body class="hold-transition skin-blue sidebar-mini" style="background:#ecf0f5;">

<section class="content" id="vbody">

    <?php if($error) : ?>
        <div class="alert alert-warning alert-dismissible">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            <span><?php echo $error; ?></span>
        </div>
    <?php endif ?>
    <?php if($success) : ?>
        <div class="alert alert-success alert-dismissible">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
            <h4><i class="icon fa fa-check"></i> 成功</h4>
            <?php echo $success; ?>
        </div>
    <?php endif ?>

    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title"><i class="fa fa-search"></i> 充值兑换账户信息</h3>
        </div>

        <div class="box-body">
            <table id="example1" class="table table-bordered table-striped dataTable table-hover" role="grid" aria-describedby="example1_info">
                <thead>
                <tr>
                    <th class="" rowspan="1" colspan="1" width="120">ID</th>
                    <th class="" rowspan="1" colspan="1" width="120">功能</th>
                    <th class="" rowspan="1" colspan="1" width="120">渠道</th>
                    <th class="" rowspan="1" colspan="1" width="200">名字</th>
                    <th class="" rowspan="1" colspan="1" width="200">账号</th>
                    <th class="" rowspan="1" colspan="1">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php if(!empty($show_config)) { foreach($show_config as $user) { ?>
                <tr role="row" style="text-align:center;">
                    
                    <td><?php echo $user['id']; ?></td>
                    <?php if($user['ef'] == 1) : ?>
                    <td>充值</td>
                    <?php  elseif($user['ef'] == 2) : ?>
                    <td>兑换</td>
                    <?php endif ?>

                    <?php if($user['qd'] == 'wx') : ?>
                    <td>微信</td>
                    <?php  elseif($user['qd'] == 'zfb') : ?>
                    <td>支付宝</td>
                    <?php endif ?>
                    <td><?php echo $user['name']; ?></td>
                    <td><?php echo $user['number']; ?></td>
                    <td style="text-align:left;">
                    <button type="button" stockvalueid="<?php echo $user['id']; ?>" startscore="<?php echo $user['name']; ?>" coefficient="<?php echo $user['number']; ?>" class="btn btn-primary" data-toggle="modal" data-target="#modal-edit-gold">修改值</button> 
                    </td>
                </tr>
                <?php } } ?>
                </tbody>
            </table>
            
        </div>
    </div>


    <div class="modal fade" id="modal-edit-gold"><div class="modal-dialog"><div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">修改参数</h4></div>
        <div class="modal-body">
            <label>id</label>
            <input type="text" readonly="readonly" id="modal_gold_num3" class="form-control" style="display:inline-block;width:200px;margin-left:50px;font-size:16px;" value="0" />
            <br/>
            <br/>
            <label>名字</label>
            <input type="text" id="modal_gold_num1" class="form-control" style="display:inline-block;width:200px;margin-left:50px;font-size:16px;" value="0" />
            <br/>
            <br/>
            <label>账号</label>
            <input type="text" id="modal_gold_num2" class="form-control" style="display:inline-block;width:200px;margin-left:50px;font-size:16px;" value="0" />

        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>
            <button type="button" class="btn btn-primary" id="click_add_gold">确定</button>
        </div>
    </div></div></div>
</section>

<!-- jQuery 3 -->
<script src="http://gold-static.91changwan.com/web/manage_static/js/jquery.min.js"></script>
<script src="http://gold-static.91changwan.com/web/manage_static/js/jquery.cookie.js"></script>
<script src="http://gold-static.91changwan.com/web/manage_static/js/vue.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="http://gold-static.91changwan.com/web/manage_static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Select2 -->
<script src="http://gold-static.91changwan.com/web/manage_static/bower_components/select2/dist/js/select2.full.min.js"></script>
<!-- InputMask -->
<script src="http://gold-static.91changwan.com/web/manage_static/plugins/input-mask/jquery.inputmask.js"></script>
<script src="http://gold-static.91changwan.com/web/manage_static/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="http://gold-static.91changwan.com/web/manage_static/plugins/input-mask/jquery.inputmask.extensions.js"></script>
<!-- date-range-picker -->
<script src="http://gold-static.91changwan.com/web/manage_static/bower_components/moment/min/moment.min.js"></script>
<script src="http://gold-static.91changwan.com/web/manage_static/bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- bootstrap datepicker -->
<script src="http://gold-static.91changwan.com/web/manage_static/bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<!-- bootstrap time picker -->
<script src="http://gold-static.91changwan.com/web/manage_static/plugins/timepicker/bootstrap-timepicker.min.js"></script>
<!-- SlimScroll -->
<script src="http://gold-static.91changwan.com/web/manage_static/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- iCheck 1.0.1 -->
<script src="http://gold-static.91changwan.com/web/manage_static/plugins/iCheck/icheck.min.js"></script>
<!-- FastClick -->
<script src="http://gold-static.91changwan.com/web/manage_static/bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="http://gold-static.91changwan.com/web/manage_static/dist/js/adminlte.min.js"></script>
<script type="text/javascript">
    var app = new Vue({
        el: '#vbody',
        data: {
        },
        watch: {
        },
        methods: {
        }
    });

    $(function() {
        var locale = {
            "format": 'YYYY-MM-DD',
            "separator": " -222 ",
            "applyLabel": "确定",
            "cancelLabel": "取消",
            "fromLabel": "起始时间",
            "toLabel": "结束时间'",
            "customRangeLabel": "自定义",
            "weekLabel": "W",
            "daysOfWeek": ["日", "一", "二", "三", "四", "五", "六"],
            "monthNames": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
            "firstDay": 1
        };

        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass   : 'iradio_minimal-blue'
        })
        //Red color scheme for iCheck
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
            checkboxClass: 'icheckbox_minimal-red',
            radioClass   : 'iradio_minimal-red'
        })
        $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
            checkboxClass: 'icheckbox_flat-green',
            radioClass   : 'iradio_flat-green'
        });

        

        $('input[name="start"]').daterangepicker({
            locale: locale,
            singleDatePicker: true,
            showDropdowns: true,
            minYear: 1901,
            maxYear: parseInt(moment().format('YYYY'),10)
        }, function(start) {
            //$('#search_start_date').val(start.format('YYYY-MM-DD'));
        });

        $('input[name="end"]').daterangepicker({
            locale: locale,
            singleDatePicker: true,
            showDropdowns: true,
            minYear: 1901,
            maxYear: parseInt(moment().format('YYYY'),10)
        }, function(end) {
            //$('#search_end_date').val(end.format('YYYY-MM-DD'));
        });


        $('#modal-edit-gold').on('show.bs.modal', function (e) {
            var btn = $(e.relatedTarget);
            var modal = $(this);

            var startscore = $(btn).attr('startscore');
            $('#modal_gold_num1').val(startscore);
            var coefficient = $(btn).attr('coefficient');
            $('#modal_gold_num2').val(coefficient);
            var stockvalueid = $(btn).attr('stockvalueid');
            $('#modal_gold_num3').val(stockvalueid);
        });


        // 修改金币
        $('#click_add_gold').click(function() {
            var _startscore = $('#modal_gold_num1').val().trim();
            var _coefficient = $('#modal_gold_num2').val().trim();
            var _stockvalueid = $('#modal_gold_num3').val().trim();

            if(!_stockvalueid || isNaN(_stockvalueid)) {
                alert('错误的数字'); return false;
            }

            var _this = this;
            
            $.ajax({
                url: 'player_action.php?action=change_configedit&id='+_stockvalueid+'&name='+_startscore+'&number='+_coefficient,
                beforeSend: function() {
                    $(_this).hide();
                    $(_this).parent().append('<span class="load"><img src="http://static.91changwan.com/ajax-loader.gif" /> ...</span>');
                },
                success: function(data) {
                    location.reload();
                    // if(data == 'OK') location.reload();
                    // else {
                    //     if(data == 'AUTH') alert('无权限,无法修改');
                    //     else alert('修改失败');
                    // }
                    $(_this).parent().find('.load').remove();
                    $(_this).show();
                }
            });
        });


        setTimeout(function() {
            $('.alert-success').fadeOut();
            if($('.alert-warning').find('span').html() && $('.alert-warning').find('span').html().length < 60) {
                $('.alert-warning').fadeOut();
            }
        }, 2000);
    });
</script>

</body>
</html>
